package org.edu.modules.portal.controller;

import com.github.xiaoymin.knife4j.annotations.ApiSort;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.edu.common.api.vo.Result;
import org.edu.common.aspect.annotation.AutoLog;
import org.edu.common.system.base.controller.BaseController;
import org.edu.modules.portal.entity.VeCuzSite;
import org.edu.modules.portal.service.IVeCuzSiteService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = {"课程网站信息"})
@RestController
@RequestMapping({"/portal/veCuzSite"})
@ApiSort(110)
public class VeCuzSiteController
        extends BaseController<VeCuzSite, IVeCuzSiteService> {
    private static final Logger log = LoggerFactory.getLogger(org.edu.modules.portal.controller.VeCuzSiteController.class);


    @Autowired
    private IVeCuzSiteService veCuzSiteService;


    @AutoLog("ve_cuz_site-通过CourseId查询")
    @ApiOperation(value = "通过课程id查询", notes = "ve_cuz_site-通过CourseId查询")
    @PostMapping({"/queryByCourseId"})
    public Result<?> queryByCourseId(@RequestParam(name = "courseid", required = true) String courseid) {
        VeCuzSite veCuzSite = this.veCuzSiteService.getByCourseId(courseid);
        if (veCuzSite == null) {
            return Result.error("未找到对应数据");
        }
        return Result.OK(veCuzSite);
    }


    @AutoLog("ve_cuz_site-通过id查询")
    @ApiOperation(value = "通过id查询", notes = "ve_cuz_site-通过id查询")
    @PostMapping({"/queryById"})
    public Result<?> queryById(@RequestParam(name = "id", required = true) String id) {
        VeCuzSite veCuzSite = (VeCuzSite) this.veCuzSiteService.getById(id);
        if (veCuzSite == null) {
            return Result.error("未找到对应数据");
        }
        return Result.OK(veCuzSite);
    }


    @AutoLog("ve_cuz_site-新增信息")
    @ApiOperation(value = "新增信息", notes = "ve_cuz_site-新增信息")
    @PostMapping({"/add"})
    public Result<?> add(@RequestBody VeCuzSite veCuzSite) {
        if (this.veCuzSiteService.save(veCuzSite)) {
            return Result.OK("添加成功！");
        }
        return Result.error("操作失败");
    }


    @AutoLog("ve_cuz_site-修改信息")
    @ApiOperation(value = "修改信息", notes = "ve_cuz_site-修改信息")
    @PostMapping({"/edit"})
    public Result<?> edit(@RequestBody VeCuzSite veCuzSite) {
        if (this.veCuzSiteService.updateById(veCuzSite)) {
            return Result.OK("编辑成功!");
        }
        return Result.error("操作失败");
    }
}



